package vpfarm.master;

import jtools.ai.agenten.AID;
import jtools.ai.agenten.AMessage;
import jtools.ai.agenten.CycleBehavior;
import vpfarm.Constants;
import vpfarm.data.RenderTask;

public class JobSwitchBehavior extends CycleBehavior {

	private Master master;

	public JobSwitchBehavior(Master master) {
		this.master = master;
	}

	public void execute() {
		AMessage msg = myAgent.reciveMessage(true);
		if (msg.getSubject() == Constants.ASK_FOR_RENDER_TASK){
			AID sender = msg.getSender();
			RenderTask rt = this.master.createRendertask(sender);
			if (rt == null)
				return;
			AMessage rep = msg.createReplay(Constants.SEND_RENDER_TASK);
			rep.setContent(rt);
			myAgent.sendMessage(rep);
		}else
			myAgent.pushBack(msg);
	}

	public void onEnd() {
	}

	public void onStart() {
	}

}
